import os
import sys

curpath = os.path.dirname(os.path.abspath(__file__)) + "/../../utility"
sys.path.append(curpath)
from utility.graph_base import GraphBase
import json


class GraphSongs(GraphBase):

    def __init__(self, json_data):
        super().__init__()
        self.__items = json_data

    def create_edge(self, batchids):
        retlist = []
        for x in batchids:
            if 'album' in self.__items[x]:
                for i in self.__items[x]['album']:
                    retlist.append((self.__items[x]['songName'][0], i))
        return retlist


if __name__ == "__main__":
    jsonpath = os.path.dirname(os.path.abspath(__file__)) + "/../../data/data.json"
    json_str = json.load(open(jsonpath))
    tester = GraphSongs(json_str)
    tester.prepare_graph(list(json_str.keys()))
